package com.xqls.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.xqls.bean.BlockBean;
import com.xqls.biz.BlockBiz;
import com.xqls.util.CommonResult;

@Controller
@RequestMapping("/block")
public class BlockController {

	@Autowired private BlockBiz blockBiz;
	
	@RequestMapping("/index")
	public ModelAndView index(){
		ModelAndView view = new ModelAndView("block/blockIndex");
		return view;
	}
	
	@RequestMapping("/{isAll}/select")
	@ResponseBody
	public String select(@PathVariable(value="isAll") boolean isAll){
       return JSONObject.toJSONString(blockBiz.queryList(isAll));
	}
	
	@RequestMapping("/treeData")
	@ResponseBody
	public String treeData(){
		return JSONObject.toJSONString(blockBiz.queryList(false));
	}
	
	@RequestMapping("/edit")
	@ResponseBody
	public String edit(BlockBean bean){
		CommonResult result = blockBiz.edit(bean);
		return JSONObject.toJSONString(result);
	}
	
	@RequestMapping("/remove")
	@ResponseBody
	public String remove(@RequestParam("id") Integer key){
		return JSONObject.toJSONString(blockBiz.remove(key));
	}
}
